package edu.lnu.project.timeeditapp.activites;

import com.lnu.project.timeeditapp.R;

import edu.lnu.project.timeeditapp.db.TimeEditDataSource;
import edu.lnu.project.timeeditapp.db.TimeEditDbHelper;
import edu.lnu.project.timeeditapp.parser.Event;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

//TODO: Change the name of this class because it's confusing with the EventDetailedDialog.
//This activity will show up when an event is clicked on the reminder.
@SuppressWarnings("deprecation")
public class DetailedEventScreen extends Activity {

	TimeEditDataSource datasource;
	Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mContext = this.getApplicationContext();
		super.onCreate(savedInstanceState);
		setContentView(R.layout.event_dialog);
		RadioGroup reminderRadioGroup = (RadioGroup) findViewById(R.id.reminder_radio_group);
		reminderRadioGroup.setVisibility(View.GONE);

		//Get the event id from the intent that started this activity.
		Intent intent = getIntent();
		int eventId = Integer.parseInt(intent.getExtras().get(TimeEditDbHelper.COLUMN_ID).toString());

		//Initialize the datasource and get the event according to its id.
		datasource = new TimeEditDataSource(this.getApplicationContext());
		datasource.open();
		Event event = datasource.getEvent(eventId);
		datasource.close();
		
		//Set the attributes of the layout.
		LinearLayout eventLinearLayout = (LinearLayout)findViewById(R.id.eventDialogId);
		eventLinearLayout.setGravity(Gravity.CENTER);
		eventLinearLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.background2));
		eventLinearLayout.setOrientation(LinearLayout.VERTICAL);

		LinearLayout eventSubLinearLayout = (LinearLayout)findViewById(R.id.eventDialogLayout);
		eventSubLinearLayout.setScaleX(1.3f);
		eventSubLinearLayout.setScaleY(1.3f);
		LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

		layoutParams.setMargins(0, 30, 0, 0);
		eventSubLinearLayout.setLayoutParams(layoutParams);

		TextView time = (TextView)findViewById(R.id.eventDetailedViewTime);
		TextView teacher = (TextView)findViewById(R.id.eventDetailedViewTeacher);
		TextView city = (TextView)findViewById(R.id.eventDetailedViewCity);
		TextView comment = (TextView)findViewById(R.id.eventDetailedViewComment);
		TextView room = (TextView)findViewById(R.id.eventDetailedViewRoom);
		TextView name = (TextView)findViewById(R.id.eventDetailedViewName);

		Button remindMe = (Button)findViewById(R.id.remindMe);
		Button dontRemind = (Button)findViewById(R.id.dontRemind);
		TextView reminderIcon = (TextView)findViewById(R.id.reminderIcon);

		remindMe.setVisibility(View.GONE);
		dontRemind.setVisibility(View.GONE);
		reminderIcon.setVisibility(View.GONE);

		time.setText("Begin time - End time: "+event.getBeginTime().toString()+" - "+event.getEndTime().toString());
		teacher.setText("Teacher: "+event.getTeacher().toString());
		city.setText("City: "+event.getCity().toString());
		comment.setText("Comments: "+event.getComments().toString());
		room.setText("Room: "+event.getRoom().toString());
		name.setText(event.getCourse());

		//Create the "Ok" button and add it to the layout.
		Button okButton = new Button(this);
		okButton.setText(android.R.string.ok);
		okButton.setGravity(Gravity.CENTER);
		LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

		layoutParams2.setMargins(0, 30, 0, 0);
		okButton.setLayoutParams(layoutParams2);
		okButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		eventLinearLayout.addView(okButton);

	}

}
